package com.stylefeng.guns.modular.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.Hybrank;
import com.stylefeng.guns.modular.system.service.IHybrankService;
import com.stylefeng.guns.modular.system.warpper.HyBrankWarpper;

/**
 * 活跃营业部控制器
 *
 * @author fengshuonan
 * @Date 2018-05-31 11:18:29
 */
@Controller
@RequestMapping("/hybrank")
public class HybrankController extends BaseController {

    private String PREFIX = "/system/hybrank/";

    @Autowired
    private IHybrankService hybrankService;

    /**
     * 跳转到活跃营业部首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "hybrank.html";
    }

    /**
     * 跳转到添加活跃营业部
     */
    @RequestMapping("/hybrank_add")
    public String hybrankAdd() {
        return PREFIX + "hybrank_add.html";
    }

    /**
     * 跳转到修改活跃营业部
     */
    @RequestMapping("/hybrank_update/{hybrankId}")
    public String hybrankUpdate(@PathVariable Integer hybrankId, Model model) {
        Hybrank hybrank = hybrankService.selectById(hybrankId);
        model.addAttribute("item",hybrank);
        LogObjectHolder.me().set(hybrank);
        return PREFIX + "hybrank_edit.html";
    }

    /**
     * 获取活跃营业部列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String date,String name) {
    	Page<Hybrank> page = new PageFactory<Hybrank>().defaultPage();
    	List<Map<String, Object>> branks = hybrankService.selectMapsByDate(page,date,name);
    	page.setRecords((List<Hybrank>) new HyBrankWarpper(branks).warp());
        return super.packForBT(page);
    }

    /**
     * 新增活跃营业部
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Hybrank hybrank) {
        hybrankService.insert(hybrank);
        return SUCCESS_TIP;
    }

    /**
     * 删除活跃营业部
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer hybrankId) {
        hybrankService.deleteById(hybrankId);
        return SUCCESS_TIP;
    }

    /**
     * 修改活跃营业部
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Hybrank hybrank) {
        hybrankService.updateById(hybrank);
        return SUCCESS_TIP;
    }

    /**
     * 活跃营业部详情
     */
    @RequestMapping(value = "/detail/{hybrankId}")
    @ResponseBody
    public Object detail(@PathVariable("hybrankId") Integer hybrankId) {
        return hybrankService.selectById(hybrankId);
    }
}
